package com.isfto.controller;


import com.isfto.code.ResponseData;
import com.isfto.entity.tablepojo.AirLine;
import com.isfto.entity.tablepojo.PageBean;
import com.isfto.entity.tablepojo.Tickets;
import com.isfto.service.FlightInfoService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/fquery")
public class FlightInfoController extends BaseController {
    @Resource
    FlightInfoService flightInfoService;

    /**
     * 基础航班信息查询
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResponseData<Object> FlightInfoAll(Integer page, Integer pageSize) {
        PageBean pageBean = flightInfoService.FlightInfoAll(page, pageSize);
        return returnObject( pageBean );
    }
    /**
     * 进港条件查询首页
     * @param page
     * @param pageSize
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @return
     */
    @GetMapping("/enterdetailsmain")
    public ResponseData<Object> flightInfoDetailEnterMain(Integer page,Integer pageSize ,String startapcd, String endapcd,String startfptt,String endfplt) {
        PageBean pageBean = flightInfoService.flightInfoDetailEnter(startapcd, endapcd, startfptt, endfplt, page, pageSize);
        return returnObject(pageBean);
    }

    /**
     * 进港条件查询
     * @param page
     * @param pageSize
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @return
     */
    @GetMapping("/enterdetails")
    public ResponseData<Object> flightInfoDetailEnter(Integer page,Integer pageSize ,String startapcd, String endapcd,String startfptt,String endfplt) {
        PageBean pageBean = flightInfoService.flightInfoDetailEnter(startapcd, endapcd, startfptt, endfplt, page, pageSize);
        return returnObject(pageBean);
    }
    //进港条件查询首页数据
    @GetMapping("/entermain")
    public ResponseData<Object> flightInfoEnterMain(Integer page,Integer pageSize,String startapat) {
        PageBean pageBean = flightInfoService.flightInfoEnter(page,pageSize,startapat);
        return returnObject(pageBean);
    }
    //出港条件查询首页数据
    @GetMapping("/outmain")
    public ResponseData<Object> flightInfoOutMain(Integer page, Integer pageSize,String endapat) {
        PageBean pageBean = flightInfoService.flightInfoOut(page, pageSize,endapat);
        return returnObject(pageBean);

    }
    /**
     * 进港条件查询数据
     * @param page
     * @param pageSize
     * @return
     */
   @GetMapping("/enter")
    public ResponseData<Object>  flightInfoEnter(Integer page,Integer pageSize,String startapat) {
        PageBean pageBean = flightInfoService.flightInfoEnter(page,pageSize,startapat);
       return returnObject(pageBean);
    }

    /**
     * 出港港条件查询数据
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/out")
    public  ResponseData<Object>  flightInfoOut(Integer page, Integer pageSize,String endapat) {
        PageBean pageBean = flightInfoService.flightInfoOut(page, pageSize,endapat);
        return returnObject(pageBean);

    }

    /**
     * 出港条件查询首页
     * @param page
     * @param pageSize
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @return
     */
    @GetMapping("/outdetailsmain")
    public ResponseData<Object> flightInfoDetailOutMain(Integer page,Integer pageSize ,String startapcd, String endapcd,String startfptt,String endfplt) {
        PageBean pageBean = flightInfoService.flightInfoDetailOut(startapcd, endapcd, startfptt, endfplt, page, pageSize);
        return returnObject(pageBean);
    }
    /**
     * 出港条件查询
     * @param page
     * @param pageSize
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @return
     */
    @GetMapping("/outdetails")
    public ResponseData<Object> flightInfoDetailOut(Integer page,Integer pageSize ,String startapcd, String endapcd,String startfptt,String endfplt) {
        PageBean pageBean = flightInfoService.flightInfoDetailOut(startapcd, endapcd, startfptt, endfplt, page, pageSize);
        return returnObject(pageBean);
    }
    @GetMapping("/airlineenter")
    public List<AirLine> enterAirLine() {
        List<AirLine> airLines = flightInfoService.enterAirLine();
        return airLines;
    }

    /**
     * 出港航线信息查询
     * @return
     */
    @GetMapping("/airlineout")
    public List<AirLine> outAirLine() {
        List<AirLine> airLines = flightInfoService.outAirLine();
        return airLines;
    }

   @GetMapping("/airlinecount")
    public ResponseData<Object> countAirLine() {
       AirLine airLine = flightInfoService.countAirLine();
       return returnObject(airLine);
    }

    @GetMapping("/outairlinecount")
    public ResponseData<Object> OutCountAirLine() {
        AirLine airLine = flightInfoService.outcountAirLine();
        return returnObject(airLine);
    }
    /**
     * 购票
     */
    @PostMapping("/tickets/buy")
    public ResponseData<Boolean> butickets(@RequestBody Tickets tickets){
        tickets.setStatus( 1 );
        flightInfoService.bytickets(tickets);
        return returnBoolean( true );
    }
    /**
     * 查询机票
     */
    @GetMapping("/gettickets")
    public ResponseData<Object> gets(){
        List<Tickets> list = flightInfoService.getstickets();
        return returnObject( list );
    }

    /**
     * 用户退票
     */
    @PostMapping("/refundTicket/{id}")
    public ResponseData<Boolean> refundTicket(@PathVariable Integer id){
        Integer status=2;
        Boolean b = flightInfoService.refundTicket( id,status );
        return returnBoolean( b );
    }
}
